{-- ======================================================================== -}

module CalcProbs where

{-Probability for all successes.-}
calcProbAll :: (Integral a, Fractional b) => a -> a -> a -> b
calcProbAll pool wins sides
  | pool < 1 || wins < 1 || sides < 1 = 0
  | sides == 1 = 1
  | otherwise =
      ((fromIntegral wins / fromIntegral sides)^pool)

{-Probability for at least one success.-}
calcProbOne :: (Integral a, Fractional b) => a -> a -> a -> b
calcProbOne pool wins sides
  | pool < 1 || wins < 1 || sides < 1 = 0
  | sides == 1 = 1
  | pool > 20 = calcProbOne (20) wins sides --For now, avoid edge cases.
  | otherwise =
      (fromIntegral wins / fromIntegral sides)
    + ((calcProbOne (pool - 1) wins sides)
        * (1 - (fromIntegral wins / fromIntegral sides)))
